#!/usr/bin/env python
#coding=utf8

import socket

def handler(conn,addr):
    print(addr)
    data = b''
    while True:
        buff = conn.recv(1024)
        data += buff
        if len(buff)<1024:
            break
    print(len(data))
    while data:
        buff = data[:1024]
        data = data[1024:]
        print(len(data),'1111111111')
        conn.send(buff)
    conn.close()


server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(('127.0.0.1',6666))
server.listen(1)
while True:
      conn,addr=server.accept()
      handler(conn,addr)
